<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
        }
        body{

          display: flex;

            
            background-image:url(./img/login-background.jpg); 
            background-repeat: no-repeat;
            background-size: cover;
        }
        .outer{
            margin: auto;
            width: 500px;
            border-radius: 10px;
            overflow: hidden;
        }
        .outer>.top{
            height: 50px;
            
            background-color: #FFFFFF;
            /* color: white; */
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 30px;
        }
        .outer>.bottom{
          background-color: white;
            display: flex;
            flex-direction: column;
            padding: 30px 0;
            justify-content: space-between;
            align-items: center;
        }
        .outer>.bottom>input{
            margin: 10px 0;
            outline: none;
            text-indent: 10px;
            width: 350px;
            height: 40px;
        }
        .outer>.bottom>section{
            width: 350px;
            display: flex;
            justify-content: left;
        }
        .outer>.bottom>.login{
            background-color: #5be85b;
            border: none;
            width: 100px;
            color: white;
            text-indent: 0;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="top">后台管理系统</div>
        <div class="bottom">
            <input type="text" name="" id="" placeholder="注册">
            <input type="password" name="" id="" placeholder="密码">
            <input type="password" name="" id="" placeholder="确认密码">
            <section>
                <a href="./login.html">使用已有账号去登录</a>
            </section>
           <input class="login" type="button" value="注册">
        </div>
    </div>
</body>
</html>
<script src="./axios.min.js"></script>
<script>
    var input=document.querySelectorAll('.bottom input')
    input[1].onblur=function(){
        var sj= /^1[3-9]\d{9}$/.test(input[1].value)
          if(sj==false){
            alert('请输入正确的手机号')
          }
    }
    input[4].onblur=function(){
        var you=/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(input[4].value)
          if(you==false){
            alert('请输入正确格式的邮箱')
          }
    }
    input[3].onblur=function(){
        if(input[2].value != input[3].value){
            alert('密码不一致')
        }
    }
    input[5].onclick=function(){
        if(input[1].value && input[2].value && input[3].value && input[4].value && input[0].value){
            axios.post('/user/register',{name:input[0].value,phone:input[1].value,email:input[4].value,mima:input[2].value}).then((res)=>{
                if(res.data.msg=='注册成功'){
                    location.href='/login.html'
                }else{
                    alert('手机号被占用')
                }
                console.log(res.data)
            })
        }else{
            alert('请输入内容后再注册')
        }
    }
</script>